package ptaTest5;

import java.util.*;
public class Test554{

    @SuppressWarnings("unchecked")
	public static void main(String[] args) {
        @SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
        Map<String,ArrayList<Integer>> word=new TreeMap<String,ArrayList<Integer>>();
        List<String> list=new ArrayList<String>();
        ArrayList<Integer> what=new ArrayList<Integer>();
        String str=null;
        while(true)
        {
            str=sc.nextLine();
            if(str.equals("!!!!!"))break;
            list.add(str);
            String[] sttr=str.split(" ");
            for(int i=0;i<sttr.length;i++)
            {
                if(word.containsKey(sttr[i]))
                {
                    if(!word.get(sttr[i]).contains(list.size()))
                    word.get(sttr[i]).add( list.size());
                }
                else
                {
                    word.put(sttr[i],new ArrayList<Integer>());
                    word.get(sttr[i]).add(list.size());
                }

            }

        }


        for(Map.Entry<String,ArrayList<Integer>> entry:word.entrySet())
        {
            System.out.println(entry.getKey()+'='+entry.getValue().toString());
        }


        while(sc.hasNext())
        {
            String[] keyword=sc.nextLine().split(" ");
            if(!word.containsKey(keyword[0]))
            {
                System.out.println("found 0 results");
                continue;
            }
            what=(ArrayList<Integer>) word.get(keyword[0]).clone();
            for(int i=1;i<keyword.length;i++)
            {
                if(!word.containsKey(keyword[i]))
                {
                    what.clear();
                    break;
                }
                for(int j=0;j<what.size();j++)
                {
                    boolean t=false;
                    for(int k=0;k<word.get(keyword[i]).size();k++)
                    {

                        if(word.get(keyword[i]).get(k)==what.get(j))t=true;
                    }
                    if(t==false)
                    {
                        what.remove(j);
                        j--;
                    }

                }
            }
            if(what.size()==0) System.out.println("found 0 results");
            else
            {
                System.out.println(what);
                for(int i=0;i<what.size();i++)
                {
                    System.out.println("line "+what.get(i)+':'+list.get(what.get(i)-1));
                }
            }
            what.clear();
        }

    }

}
